import { Controller, Get, Post, UploadedFiles, UseInterceptors, Body, Query, Param } from '@nestjs/common';
import { BiliService } from '@/modules/bili/bili.service';
import { FileInterceptor, FileFieldsInterceptor } from '@nestjs/platform-express';
import { Express } from 'express';
import { BiliBindService } from "@/modules/bili/bili.bind.service";
import { BiliOtherService } from './bili.other.service';

@Controller("bili")
export class BiliController {
  constructor(
    private readonly biliService: BiliService,
    private readonly biliBindService: BiliBindService,
    private readonly biliOtherService: BiliOtherService,
  ) {
  }

  @Post("publish")
  @UseInterceptors(FileFieldsInterceptor([
    { name: 'cover', maxCount: 1 },
    { name: 'video', maxCount: 1 },
  ]))
  publish(@UploadedFiles() files: {cover: Express.Multer.File[], video: Express.Multer.File[]}, @Body() options: any) {
    const opt = {
      videoFile: files.video[0],
      coverFile: files.cover[0],
      config: options
    }
    // return this.biliService.publish(opt)
  }

  @Get("/debug")
  debug() {
    return this.biliService.getTypeList()
  }

  @Get("/bind/prepare")
  authPrepare() {
    return this.biliBindService.prepare(1)
  }

  @Get("/bind/check")
  authCheck(@Query() query: { hash: string }) {
    return this.biliBindService.check(query.hash)
  }

  @Get("typelist")
  getTypeList() {
    return this.biliService.getTypeList()
  }

  @Get("videolist")
  getVideoList(@Query() query: {mid: string, tid: string, pn?: number, ps?: number, last_date?: number}) {
    return this.biliOtherService.getVideoList(query)
  }
  @Get("video/download")
  downloadVideos() {
    return this.biliOtherService.downloadVideos()
  }
  @Get("video/profile/:id")
  getVideoProfile(@Param("id") id: string) {
    return this.biliOtherService.getVideoProfile(id)
  }
}